package com.xy.blog.user.controller;

import com.xy.blog.core.exception.BaseException;
import com.xy.blog.core.springmvc.controller.BaseController;
import com.xy.blog.core.springmvc.controller.IBaseController;
import com.xy.blog.core.springmvc.result.page.PageReq;
import com.xy.blog.user.controller.model.req.UserTemplateReq;
import com.xy.blog.user.controller.model.req.query.UserTemplateQuery;
import com.xy.blog.user.mapstruct.UserTemplateConverter;
import com.xy.blog.user.service.IUserTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zanhonglei
 * @version V1.0
 * @Description:
 * @date 2019/11/17 9:32 下午
 */
@Api(value = "UserTemplateController",tags = "用户模版管理")
@RequestMapping("/v1/user-template")
@RestController
public class UserTemplateController extends BaseController implements IBaseController<UserTemplateQuery, UserTemplateReq> {

    @Autowired
    private IUserTemplateService userTemplateServiceImpl;

    @Autowired
    private UserTemplateConverter userTemplateConverter;

    @Override
    public Object pages(PageReq<UserTemplateQuery> req) throws BaseException {
        return getPageData(userTemplateServiceImpl.listUserTemplate(req));
    }

    /**
     * 根据用户模板id获取该模板下所有属性
     * @param id
     * @return
     * @throws BaseException
     */
    @Override
    public Object getById(Long id) throws BaseException {
        return getData(userTemplateServiceImpl.listUserTemplateAttrByTemplateId(id));
    }

    @Override
    public Object save(@Valid UserTemplateReq userTemplateReq) throws BaseException {
        return null;
    }

    @Override
    public Object update(@Valid UserTemplateReq userTemplateReq) throws BaseException {
        return null;
    }

    @Override
    public Object deleteById(Long id) throws BaseException {
        userTemplateServiceImpl.deleteById(id);
        return success();
    }

    @GetMapping("/list-all")
    @ApiOperation(value = "查询所有", notes = "查询所有", httpMethod = "GET")
    public Object listByName(String name) {
        return getData(userTemplateServiceImpl.listByName(name));
    }
}

